﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonDB
{
    /// <summary>
    /// 数据库操作接口
    /// </summary>
    public interface IDbOperator : IDisposable
    {
        IDbProvider DbProvider { get; }

        /// <summary>
        /// 返回受影响行数
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <returns></returns>
        int ExecuteNonQuery(string sqlString);

        /// <summary>
        /// 返回受影响行数
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否为存储过程</param>
        /// <returns></returns>
        int ExecuteNonQuery(string sqlString, bool isProcedure);

        /// <summary>
        /// 返回受影响行数
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="parameters">sql语句对应参数</param>
        /// <returns></returns>
        int ExecuteNonQuery(string sqlString, params IDataParameter[] parameters);

        /// <summary>
        /// 返回受影响行数
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否为存储过程, true为存储过程</param>
        /// <param name="parameters">sql语句对应参数</param>
        /// <returns></returns>
        int ExecuteNonQuery(string sqlString, bool isProcedure, params IDataParameter[] parameters);

        /// <summary>
        /// 返回受影响行数(执行事务时使用)
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="parameters">sql语句对应参数</param>
        /// <returns></returns>
        int TransExecuteNonQuery(string sqlString, params IDataParameter[] parameters);

        /// <summary>
        /// 返回受影响行数(执行事务时使用)
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否为存储过程,true 为存储过程</param>
        /// <param name="parameters">sql语句对应参数</param>
        /// <returns></returns>
        int TransExecuteNonQuery(string sqlString, bool isProcedure, params IDataParameter[] parameters);
        
        /// <summary>
        /// 返回查询语句第一行第一列
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <returns></returns>
        object ExecuteScalar(string sqlString);

        /// <summary>
        /// 返回查询语句第一行第一列
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否是存储过程</param>
        /// <returns></returns>
        object ExecuteScalar(string sqlString, bool isProcedure);

        /// <summary>
        /// 返回查询语句第一行第一列
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="parameters">sql语句对应输入参数</param>
        /// <returns></returns>
        object ExecuteScalar(string sqlString, params IDataParameter[] parameters);

        /// <summary>
        /// 返回查询语句第一行第一列
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否为存储过程</param>
        /// <param name="parameters">sql语句对应输入参数</param>
        /// <returns></returns>
        object ExecuteScalar(string sqlString, bool isProcedure, params IDataParameter[] parameters);

        /// <summary>
        /// 返回数据只读游标集
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <returns></returns>
        IDataReader ExecuteDataReader(string sqlString);

        /// <summary>
        /// 返回数据只读游标集
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否为存储过程</param>
        /// <returns></returns>
        IDataReader ExecuteDataReader(string sqlString, bool isProcedure);

        /// <summary>
        /// 返回数据只读游标集
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="parameters">sql语句对应输入参数</param>
        /// <returns></returns>
        IDataReader ExecuteDataReader(string sqlString, params IDataParameter[] parameters);

        /// <summary>
        /// 返回数据只读游标集
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否为存储过程</param>
        /// <param name="parameters">sql语句对应输入参数</param>
        /// <returns></returns>
        IDataReader ExecuteDataReader(string sqlString, bool isProcedure, params IDataParameter[] parameters);

        /// <summary>
        /// 获得数据表结构集合
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <returns></returns>
        DataTable ExecuteTable(string sqlString);

        /// <summary>
        ///  获得数据表结构集合
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否为存储过程</param>
        /// <returns></returns>
        DataTable ExecuteTable(string sqlString, bool isProcedure);

        /// <summary>
        /// 获得数据表结构集合
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="parameters">sql语句对应参数</param>
        /// <returns></returns>
        DataTable ExecuteTable(string sqlString, params IDataParameter[] parameters);

        /// <summary>
        /// 获得数据表结构集合
        /// </summary>
        /// <param name="sqlString">sql语句</param>
        /// <param name="isProcedure">是否为存储过程</param>
        /// <param name="parameters">sql语句对应参数</param>
        /// <returns></returns>
        DataTable ExecuteTable(string sqlString, bool isProcedure, params IDataParameter[] parameters);
    }
}
